package cn.yunhe.servlet;

import cn.yunhe.entity.User;
import cn.yunhe.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UserModifyServlet")
public class UserModifyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int uid = Integer.parseInt(request.getParameter("userid"));
         String name = request.getParameter("username");
        String uname = request.getParameter("userusername");
        String  pwd= request.getParameter("userpwd");
        String  address = request.getParameter("useraddress");
        String email = request.getParameter("useremail");
        int flag = Integer.parseInt(request.getParameter("userflag"));

        User user = new User( uid,name,uname,pwd,address,email,flag);
        UserService userService = new UserService();

           boolean fla =  userService.updateUser(user);
        System.out.println(fla);
           if (fla){
               response.sendRedirect("UserByPageServlet");
           }else{
               response.sendRedirect("manage/user-modify.jsp");
           }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request,response);
    }
}
